package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.Setmeal;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@SuppressWarnings("ALL")
/**
 * @Description :
 * @author     :LD
 */
public interface SetMealMapper extends BaseMapper<Setmeal> {
    @Insert("insert into t_setmeal_checkgroup values(#{id},#{groupId})")
    void addSetMealAndCheckGroupInfos(@Param("id")Integer id, @Param("groupId") Integer groupId);

    @Select("select CHECKGROUP_ID from t_setmeal_checkgroup where SETMEAL_ID=#{id}")
    Integer[] findGroupById(@Param("id")Integer id);

    @Delete("delete from t_setmeal_checkgroup where SETMEAL_ID=#{id}")
    void deleteGroup(@Param("id") Integer id);

    @Select("select g.id,g.name,g.remark from t_setmeal_checkgroup s,t_checkgroup g where s.checkgroup_id=g.id and s.setmeal_id=#{id} and g.is_delete=0")
    List<CheckGroup> findCheckGroupsBySetmealId(@Param("id") Integer id);

    @Select("select s.name name,count(r.setmeal_id) value from t_order r,t_setmeal s where r.setmeal_id=s.id group by r.setmeal_id")
    List<Map> getSetmealProportion();

    @Select("SELECT s.*\n" +
            "FROM t_order r,t_setmeal s\n" +
            "where s.id=r.SETMEAL_ID and is_delete=0\n" +
            "group by s.id\n" +
            "ORDER BY count(s.id) desc\n" +
            "limit 0,10")
    List<Setmeal> findHot();
}
